export default class Svg2Png {

  constructor() {
    this.scale = 1;
    this.size = 100;
    this.icons = {
      "线": {
        draw: function (ctx) {
          ctx.save();
          ctx.strokeStyle = "rgba(0,0,0,0)";
          ctx.miterLimit = 4;
          ctx.font = "normal normal 400 normal 15px / 21.4286px ''";
          ctx.save();
          ctx.save();
          ctx.fillStyle = "rgba(255,255,255,0)";
          ctx.beginPath();
          ctx.moveTo(-1, -1);
          ctx.lineTo(51, -1);
          ctx.bezierCurveTo(51, -1, 51, -1, 51, -1);
          ctx.lineTo(51, 51);
          ctx.bezierCurveTo(51, 51, 51, 51, 51, 51);
          ctx.lineTo(-1, 51);
          ctx.bezierCurveTo(-1, 51, -1, 51, -1, 51);
          ctx.lineTo(-1, -1);
          ctx.bezierCurveTo(-1, -1, -1, -1, -1, -1);
          ctx.closePath();
          ctx.fill();
          ctx.stroke();
          ctx.restore();
          ctx.restore();
          ctx.save();
          ctx.fillStyle = "rgba(255,255,255,0)";
          ctx.lineWidth = 1.5;
          ctx.globalAlpha = 0;
          ctx.beginPath();
          ctx.moveTo(5.5, 56.4375);
          ctx.fill();
          ctx.stroke();
          ctx.restore();
          ctx.save();
          ctx.strokeStyle = "#000";
          ctx.lineWidth = 1.5;
          ctx.globalAlpha = 0.5;
          ctx.beginPath();
          ctx.moveTo(16.5, 45.4375);
          ctx.fill();
          ctx.stroke();
          ctx.restore();
          ctx.save();
          ctx.fillStyle = "rgba(255,255,255,0)";
          ctx.strokeStyle = "rgba(0, 0, 0, NaN)";
          ctx.lineWidth = 2.5;
          ctx.lineCap = "null";
          ctx.lineJoin = "null";
          ctx.beginPath();
          ctx.moveTo(5.5, 6.437498);
          ctx.lineTo(41.499997, 44.437499);
          ctx.fill();
          ctx.stroke();
          ctx.restore();
        },
        type: 1,
      },
      "面": {
        draw: function (ctx) {
          ctx.save();
          ctx.strokeStyle = "rgba(0,0,0,0)";
          ctx.miterLimit = 4;
          ctx.font = "normal normal 400 normal 15px / 21.4286px ''";
          ctx.save();
          ctx.fillStyle = "rgba(255,255,255,0)";
          ctx.beginPath();
          ctx.moveTo(-1, -1);
          ctx.lineTo(51, -1);
          ctx.bezierCurveTo(51, -1, 51, -1, 51, -1);
          ctx.lineTo(51, 51);
          ctx.bezierCurveTo(51, 51, 51, 51, 51, 51);
          ctx.lineTo(-1, 51);
          ctx.bezierCurveTo(-1, 51, -1, 51, -1, 51);
          ctx.lineTo(-1, -1);
          ctx.bezierCurveTo(-1, -1, -1, -1, -1, -1);
          ctx.closePath();
          ctx.fill();
          ctx.stroke();
          ctx.restore();
          ctx.restore();
          ctx.save();
          ctx.save();
          ctx.fillStyle = "rgba(255,255,255,0)";
          ctx.strokeStyle = "#000";
          ctx.lineWidth = 1.5;
          ctx.globalAlpha = 0;
          ctx.beginPath();
          ctx.moveTo(5.5, 56.4375);
          ctx.fill();
          ctx.stroke();
          ctx.restore();
          ctx.save();
          ctx.fillStyle = "#fff";
          ctx.strokeStyle = "#000";
          ctx.lineWidth = 1.5;
          ctx.font = "   15px ";
          ctx.globalAlpha = 0;
          ctx.beginPath();
          ctx.moveTo(16.5, 45.4375);
          ctx.fill();
          ctx.stroke();
          ctx.restore();
          ctx.save();
          ctx.fillStyle = "rgba(0,0,0,0)";
          ctx.strokeStyle = "#000";
          ctx.strokeStyle = "rgba(0, 0, 0, NaN)";
          ctx.lineWidth = 2.5;
          ctx.font = "   15px ";
          ctx.globalAlpha = 0;
          ctx.beginPath();
          ctx.moveTo(24.782607, 12.599648);
          ctx.fill();
          ctx.stroke();
          ctx.restore();
          ctx.save();
          ctx.fillStyle = "rgba(0,0,0,0)";
          ctx.strokeStyle = "#000";
          ctx.strokeStyle = "rgba(0, 0, 0, NaN)";
          ctx.lineWidth = 2.5;
          ctx.font = "   15px ";
          ctx.globalAlpha = 0;
          ctx.beginPath();
          ctx.moveTo(17.101453, 19.266309);
          ctx.fill();
          ctx.stroke();
          ctx.restore();
          ctx.save();
          ctx.fillStyle = "rgba(0,0,0,0)";
          ctx.strokeStyle = "#000";
          ctx.strokeStyle = "rgba(0, 0, 0, NaN)";
          ctx.lineWidth = 2.5;
          ctx.beginPath();
          ctx.moveTo(26.666663, 5.063422);
          ctx.lineTo(3.333331000000001, 22.898533999999998);
          ctx.lineTo(13.188396000000001, 45.65214);
          ctx.lineTo(34.782582000000005, 45.507213);
          ctx.lineTo(46.811558000000005, 26.666648);
          ctx.lineTo(26.666663000000003, 5.063423);
          ctx.closePath();
          ctx.fill();
          ctx.stroke();
          ctx.restore();
        },
        type: 2,
      },
      "定位点": {
        draw: function (ctx) {
          ctx.save();
          ctx.strokeStyle = "rgba(255,255,255,0)";
          ctx.miterLimit = 4;
          ctx.font = "normal normal 400 normal 15px / 21.4286px ''";
          ctx.save();
          ctx.save();
          ctx.fillStyle = "rgba(255,255,255,0)";
          ctx.beginPath();
          ctx.moveTo(-1, -1);
          ctx.lineTo(51, -1);
          ctx.bezierCurveTo(51, -1, 51, -1, 51, -1);
          ctx.lineTo(51, 51);
          ctx.bezierCurveTo(51, 51, 51, 51, 51, 51);
          ctx.lineTo(-1, 51);
          ctx.bezierCurveTo(-1, 51, -1, 51, -1, 51);
          ctx.lineTo(-1, -1);
          ctx.bezierCurveTo(-1, -1, -1, -1, -1, -1);
          ctx.closePath();
          ctx.fill();
          ctx.stroke();
          ctx.restore();
          ctx.restore();
          ctx.save();
          ctx.save();
          ctx.fillStyle = "rgba(255,255,255,0)";
          ctx.lineWidth = 1.5;
          ctx.globalAlpha = 0;
          ctx.beginPath();
          ctx.moveTo(5.5, 56.4375);
          ctx.fill();
          ctx.stroke();
          ctx.restore();
          ctx.save();
          ctx.fillStyle = "rgba(0,0,0,0)";
          ctx.lineWidth = 1.5;
          ctx.globalAlpha = 0;
          ctx.beginPath();
          ctx.moveTo(16.5, 45.4375);
          ctx.fill();
          ctx.stroke();
          ctx.restore();
          ctx.save();
          ctx.fillStyle = "rgba(0,0,0,0)";
          ctx.strokeStyle = "#000";
          ctx.strokeStyle = "rgba(0, 0, 0, NaN)";
          ctx.lineWidth = 2.5;
          ctx.globalAlpha = 0;
          ctx.beginPath();
          ctx.moveTo(24.782607, 12.599648);
          ctx.fill();
          ctx.stroke();
          ctx.restore();
          ctx.save();
          ctx.fillStyle = "rgba(0,0,0,0)";
          ctx.strokeStyle = "#000";
          ctx.strokeStyle = "rgba(0, 0, 0, NaN)";
          ctx.lineWidth = 2.5;
          ctx.globalAlpha = 0;
          ctx.beginPath();
          ctx.moveTo(17.101453, 19.266309);
          ctx.fill();
          ctx.stroke();
          ctx.restore();
          ctx.save();
          ctx.fillStyle = "rgba(0,0,0,0)";
          ctx.strokeStyle = "rgba(0, 0, 0, NaN)";
          ctx.lineWidth = 2.5;
          ctx.beginPath();
          ctx.moveTo(25.909163, 10.387485);
          ctx.bezierCurveTo(19.746192, 10.387485, 14.749751999999999, 14.281423, 14.749751999999999, 19.084488);
          ctx.bezierCurveTo(14.749751999999999, 23.888711999999998, 25.909163, 40.097606, 25.909163, 40.097606);
          ctx.bezierCurveTo(25.909163, 40.097606, 37.068574, 23.888711999999998, 37.068574, 19.084488);
          ctx.bezierCurveTo(37.068574, 14.281423, 32.073622, 10.387485, 25.909163, 10.387485);
          ctx.closePath();
          ctx.moveTo(25.909163, 23.240495);
          ctx.bezierCurveTo(22.964567, 23.240495, 20.576453, 21.380496, 20.576453, 19.084487);
          ctx.bezierCurveTo(20.576453, 16.788477999999998, 22.964567000000002, 14.928479, 25.909163, 14.928479);
          ctx.bezierCurveTo(28.853758999999997, 14.928479, 31.241873, 16.789638, 31.241873, 19.084487);
          ctx.bezierCurveTo(31.241873, 21.379336, 28.853758999999997, 23.240495, 25.909163, 23.240495);
          ctx.closePath();
          ctx.fill();
          ctx.stroke();
          ctx.restore();
        },
        type: 0,
      }
    }
  }

  /**
   *
   * @param canvas
   * @returns {*}
   */
  getCanvasImageData(name, options) {
    const canvas = document.createElement('canvas');
    const ctx = canvas.getContext('2d');
    canvas.width = 50;
    canvas.height = 50;
    this.icons[name].draw(ctx);
    ctx.strokeStyle = (options || {}).strokeStyle || "#000";  //线条颜色 rgba
    ctx.fillStyle = (options || {}).fillStyle || 'rgba(255, 255, 255, 0)';      //背景色   rgba
    ctx.lineWidth = (options || {}).lineWidth / 50 || 1.5;         //背景色   rgba
    ctx.stroke();
    ctx.fill();
   // console.log(canvas.toDataURL('image/png'))
    return ctx.getImageData(0, 0, canvas.width, canvas.height);
  }


}
